xtset id year

gen logforaid = ln(foraid_percap)

***regressions, general 
reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, robust
outreg2 using 1demrecgen, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if leastdeveloped==1, robust
outreg2 using 1demrecgen, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if middeveloped==1, robust
outreg2 using 1demrecgen, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if developed==1, robust
outreg2 using 1demrecgen, word append


***regressions over time, whole sample
reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1, robust
outreg2 using 2demrecwholetime, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears, robust
outreg2 using 2demrecwholetime, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears, robust
outreg2 using 2demrecwholetime, word append


***regressions over time, leastdevt

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1 & leastdeveloped==1, robust
outreg2 using 3demrecleast, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears & leastdeveloped==1, robust
outreg2 using 3demrecleast, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears & leastdeveloped==1, robust
outreg2 using 3demrecleast, word append


***regressions over time, mid

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1 & middeveloped==1, robust
outreg2 using 4demrecmid, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears & middeveloped==1, robust
outreg2 using 4demrecmid, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears & middeveloped==1, robust
outreg2 using 4demrecmid, word append


***regressions over time, devt

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1 & developed==1, robust
outreg2 using 5demrecdev, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears & developed==1, robust
outreg2 using 5demrecdev, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears & developed==1, robust
outreg2 using 5demrecdev, word append



***regressions, intra- vs interstate wars
reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==0, robust
outreg2 using 6demrecwar, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==1, robust
outreg2 using 6demrecwar, word append

***regressions over time, interstate

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1 & intrastate==0, robust
outreg2 using 7demrecwarot2, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears & intrastate==0, robust
outreg2 using 7demrecwarot2, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears & intrastate==0, robust
outreg2 using 7demrecwarot2, word append

***regressions over time, intrastate

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if first5years==1 & intrastate==1, robust
outreg2 using 8demrecwarot, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if fivetotenyears & intrastate==1, robust
outreg2 using 8demrecwarot, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if aftertenyears & intrastate==1, robust
outreg2 using 8demrecwarot, word append

***foreign aid interaction models, income groups
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, robust
outreg2 using 9demrecint1, word append
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if leastdeveloped==1, robust
outreg2 using 9demrecint1, word append
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if middeveloped==1, robust
outreg2 using 9demrecint1, word append
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if developed==1, robust
outreg2 using 9demrecint1, word append

*marginal effects for the whole sample
grstyle clear
set scheme s2color
grstyle init
grstyle set plain, box
grstyle color background white
grstyle set color Set1
grstyle yesno draw_major_hgrid yes
grstyle yesno draw_major_ygrid yes
grstyle color major_grid gs8
grstyle linepattern major_grid dot
grstyle set legend 4, box inside
grstyle color ci_area gs12%50

reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, robust
margins, at(rpehist=(0.5(0.5)2) foraid_gdp=(0.005 0.114754))
marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea)

*** foreign aid interaction models, intra- vs interstate wars
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==0, robust
outreg2 using 10demrecint2, word append
reg poploss1 c.rpehist##c.foraid_gdp literacy loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==1, robust
outreg2 using 10demrecint2, word append

margins, at(rpehist=(0.5(0.5)2) foraid_gdp=(0.005 0.114754))
marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea)


***** ROBUSTNESS CHECKS *****
*** random effects

***regressions, general 
xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, re
outreg2 using 11demrecgenre, word append

xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if leastdeveloped==1, re
outreg2 using 11demrecgenre, word append

xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if middeveloped==1, re
outreg2 using 11demrecgenre, word append

xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if developed==1, re
outreg2 using 11demrecgenre, word append


***regressions, intra- vs interstate wars
xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==0, re
outreg2 using 12demrecwarre, word append

xtreg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==1, re
outreg2 using 12demrecwarre, word append


*** xtabond

***regressions, general 
xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs 
outreg2 using 13demrecgenxta, word append

xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs if leastdeveloped==1
outreg2 using 13demrecgenxta, word append

xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs if middeveloped==1
outreg2 using 13demrecgenxta, word append

xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs if developed==1
outreg2 using 13demrecgenxta, word append


***regressions, intra- vs interstate wars
xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs if intrastate==0
outreg2 using 14demrecwarxta, word append

xtabond poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs if intrastate==1
outreg2 using 14demrecwarxta, word append


*** Lagged DV
***regressions, general 
reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year, robust
outreg2 using 15demrecgenldv, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year if leastdeveloped==1, robust
outreg2 using 15demrecgenldv, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year if middeveloped==1, robust
outreg2 using 15demrecgenldv, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year if developed==1, robust
outreg2 using 15demrecgenldv, word append


***regressions, intra- vs interstate wars
reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year if intrastate==0, robust
outreg2 using 16demrecwarldv, word append

reg poploss1 rpehist literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner l.poploss1 i.id i.year if intrastate==1, robust
outreg2 using 16demrecwarldv, word append


***literacy interaction models, income groups
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, robust
outreg2 using 17demrecint3, word append
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if leastdeveloped==1, robust
outreg2 using 17demrecint3, word append
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if middeveloped==1, robust
outreg2 using 17demrecint3, word append
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if developed==1, robust
outreg2 using 17demrecint3, word append

reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year, robust
margins, at(rpehist=(0.5(0.5)2) literacy=(76.8))
marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea)

*** literacy interaction models, intra- vs interstate wars
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==0, robust
outreg2 using 18demrecint4, word append
reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==1, robust
outreg2 using 18demrecint4, word append

reg poploss1 c.rpehist##c.literacy foraid_gdp loggdppc gdppcloss1 population prewar_gdppc length_yrs winner i.id i.year if intrastate==1, robust
margins, at(rpehist=(0.5(0.5)2) literacy=(76.8))
marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea)
***** END ROBUSTNESS CHECKS *****


